//
//  BN_DynamicHelperTest.m
//  BabyNow
//
//  Created by iMobile on 14-4-3.
//  Copyright (c) 2014年 iMobile. All rights reserved.
//

#import <XCTest/XCTest.h>
#import "XCTestAsync.h"
#import "BN_DynamicHelper.h"

@interface BN_DynamicHelperTest : XCTestCase
{
    BN_DynamicHelper *dynamicHelper_;
    
}

- (void)xctAssertNil:(NSString*)errorMsg;
- (void)xcAsyncSuccess;

@end

@implementation BN_DynamicHelperTest

- (void)xctAssertNil:(NSString *)errorMsg{
    XCTAssertNil(errorMsg);
}

- (void)xcAsyncSuccess{
    XCAsyncSuccess();
}

- (void)setUp
{
    [super setUp];
    // Put setup code here. This method is called before the invocation of each test method in the class.
    dynamicHelper_ = [[BN_DynamicHelper alloc]init];
}

- (void)tearDown
{
    // Put teardown code here. This method is called after the invocation of each test method in the class.
    [super tearDown];
    //dynamicHelper_ = nil;
}

/**
 *  测试加载班级动态第一页
 */
- (void)testQueryFirstClassDynamicPageAsync
{
    __weak typeof(self) weakSelf = self;
    dynamicHelper_.queryClassListCompleteHandler = ^(id result,NSString *errorMsg){
        if (errorMsg) {
            [weakSelf xctAssertNil:errorMsg];
        }else{
            NSLog(@"班级动态列表:%@",result);
            [weakSelf xcAsyncSuccess];
        }
    };
    // 测试加载第一页
    [dynamicHelper_ refreshClassList];
}

/**
 *  测试加载家长动态第一页
 */
- (void)testQueryFirstParentDynamicPageAsync{
    __weak typeof(self) weakSelf = self;
    dynamicHelper_.queryParentListCompleteHandler = ^(id result,NSString *errorMsg){
        if (errorMsg) {
            [weakSelf xctAssertNil:errorMsg];
        }else{
            NSLog(@"家长动态列表:%@",result);
            [weakSelf xcAsyncSuccess];
        }
    };
    // 测试加载第一页
    [dynamicHelper_ refreshParentList];
}

// add by jason yan 2014-07-26
// 测试获取第一页家长动态新接口
- (void)testNewQueryFirstParentDynamicPageAsync{
    __weak typeof(self) weakSelf = self;
    dynamicHelper_.queryParentListCompleteHandler = ^(id result,NSString *errorMsg){
        if (errorMsg) {
            [weakSelf xctAssertNil:errorMsg];
        }else{
            NSLog(@"家长动态列表:%@",result);
            [weakSelf xcAsyncSuccess];
        }
    };
    // 测试加载第一页
    [dynamicHelper_ newRefreshParentList];
}

/**
 *  测试查询第二页班级动态
 */
- (void)testQuerySecondClassDynamicPageAsync{
    __weak typeof(self) weakSelf = self;
    dynamicHelper_.queryClassListCompleteHandler = ^(id result,NSString *errorMsg){
        if (errorMsg) {
            [weakSelf xctAssertNil:errorMsg];
        }else{
            NSLog(@"第二页班级动态列表:%@",result);
            [weakSelf xcAsyncSuccess];
        }
    };
    // 测试加载第二页班级动态
    [dynamicHelper_ fetchNextPageForClass];
}

/**
 *  测试查询第二页家长动态
 */
- (void)testQuerySecondParentDynamicPageAsync{
    __weak typeof(self) weakSelf = self;
    dynamicHelper_.queryParentListCompleteHandler = ^(id result,NSString *errorMsg){
        if (errorMsg) {
            [weakSelf xctAssertNil:errorMsg];
        }else{
            NSLog(@"第二页家长动态列表:%@",result);
            [weakSelf xcAsyncSuccess];
        }
    };
    // 测试加载第二页家长动态
    [dynamicHelper_ fetchNextPageForParent];
}



/**
 *  测试获取动态详情
 */
- (void)testQueryDynamicDetialAsync{
    __weak typeof(self) weakSelf = self;
    [dynamicHelper_ queryDetailWithPostId:@"10" completeHandler:^(id result, NSString *errMsg) {
        if (errMsg) {
            [weakSelf xctAssertNil:errMsg];
        }else{
            NSLog(@"编号为10的动态详情：%@",result);
            [weakSelf xcAsyncSuccess];
        }
    }];
    
}

/**
 *  测试回复动态信息
 */
- (void)testReplyDynamicAsync{
    __weak typeof(self) weakSelf = self;
    
    [dynamicHelper_ postReplyWithPostId:@"71" replCont:@"测试回复动态71内容" compelteHandler:^(id result, NSString *errMsg) {
        if (errMsg) {
            [weakSelf xctAssertNil:errMsg];
        }else{
            NSLog(@"回复编号为71的动态结果:%@",result);
            [weakSelf xcAsyncSuccess];
        }
    }];
}

/**
 *  测试移除动态信息
 */
- (void)testRemoveDynamicAsync{
    __weak typeof(self) weakSelf = self;
    [dynamicHelper_ removeDynamicWithPostId:@"129" completeHandler:^(id result, NSString *errMsg) {
        if (errMsg) {
            [weakSelf xctAssertNil:errMsg];
        }else{
            NSLog(@"移除编号为15的动态信息结果：%@",result);
            [weakSelf xcAsyncSuccess];
        }
    }];
}

/**
 *  测试点赞动态
 */
- (void)testSupportDynamicAsync{
    __weak typeof(self) weakSelf = self;
    int flg = 0;
    [dynamicHelper_ supportDynamicWithPostId:@"659" flg:flg completeHandler:^(id result, NSString *errMsg) {
        if (errMsg) {
            [weakSelf xctAssertNil:errMsg];
        }else{
            NSLog(@"取消点赞编号为604的动态信息结果：%@",result);
            [weakSelf xcAsyncSuccess];
        }
    }];
}

/**
 *  测试收藏动态
 */
- (void)testCollectDynamicAsync{
    __weak typeof(self) weakSelf = self;
    [dynamicHelper_ collectDynamicWithPostId:@"603" completeHandler:^(id result, NSString *errMsg) {
        if (errMsg) {
            [weakSelf xctAssertNil:errMsg];
        }else{
            NSLog(@"编号为14的动态收藏结果：%@",result);
            [weakSelf xcAsyncSuccess];
        }
    }];
    
}

// add by jason yan 2014-07-26
// 测试新动态发布接口
- (void)testNewPostImagesDynamicAsync{
    __weak typeof(self) weakSelf = self;
    NSString *content = @"测试发布两张图片和一个视频";
    NSString *fileName1 = @"320X480.png";
    NSString *imgPath1 = [[NSBundle mainBundle]pathForResource:@"320X480" ofType:@"png"];
    NSString *mimeType1 = [IMB_FileHelper mimeType:imgPath1];
    NSLog(@"image1 -> mimeType:%@",mimeType1);
    NSData *imgData1 = [NSData dataWithContentsOfFile:imgPath1];
    
    NSString *fileName2 = @"1024.png";
    NSString *imgPath2 = [[NSBundle mainBundle]pathForResource:@"1024" ofType:@"png"];
    NSString *mimeType2 = [IMB_FileHelper mimeType:imgPath2];
    NSLog(@"image2 -> mimeType:%@",mimeType2);
    NSData *imgData2 = [NSData dataWithContentsOfFile:imgPath2];
    
    NSString *fileName3 = @"1.png";
    NSString *imgPath3 = [[NSBundle mainBundle]pathForResource:@"1" ofType:@"png"];
    NSString *mimeType3 = [IMB_FileHelper mimeType:imgPath3];
    NSLog(@"image3 -> mimeType:%@",mimeType2);
    NSData *imgData3 = [NSData dataWithContentsOfFile:imgPath3];
    
    NSString *fileName4 = @"jeep.jpg";
    NSString *imgPath4 = [[NSBundle mainBundle]pathForResource:@"jeep" ofType:@"jpg"];
    NSString *mimeType4 = [IMB_FileHelper mimeType:imgPath4];
    NSLog(@"image4 -> mimeType:%@",mimeType4);
    NSData *imgData4 = [NSData dataWithContentsOfFile:imgPath4];
    
    NSString *mp4FileName4 = @"test.mp4";
    NSString *mp4FilePath4 = [[NSBundle mainBundle]pathForResource:@"test" ofType:@"mp4"];
    NSString *mp4MimeType4 = [IMB_FileHelper mimeType:mp4FilePath4];
    NSLog(@"mp4 -> mimeType:%@",mp4MimeType4);
    NSData *mp4FileData4 = [NSData dataWithContentsOfFile:mp4FilePath4];
    
    
    // 封装1张图片和一个视频
    NSArray *fileInfoArr = @[
                             @{kFileName:fileName1,kFileData:imgData1,kFileMimeType:mimeType1,kFileUploadName:kImageFile},
                             @{kFileName:fileName2,kFileData:imgData2,kFileMimeType:mimeType2,kFileUploadName:kImageFile},
                             @{kFileName:mp4FileName4,kFileData:mp4FileData4,kFileMimeType:mp4MimeType4,kFileUploadName:kVideoFile}/*,
                             @{kFileName:fileName2,kFileData:imgData2,kFileMimeType:FILE_MIME_TYPE_FOR_PNG},
                             @{kFileName:fileName3,kFileData:imgData3,kFileMimeType:FILE_MIME_TYPE_FOR_PNG},
                             @{kFileName:fileName4,kFileData:imgData4,kFileMimeType:FILE_MIME_TYPE_FOR_PNG}*/
                             ];
    // 封装一张图片，一个视频
    /*NSArray *fileInfoArr = @[
     @{kFileName:fileName1,kFileData:imgData1,kFileMimeType:mimeType1},
     @{kFileName:mp4FileName4,kFileData:mp4FileData4,kFileMimeType:mp4MimeType4}
     ];
     */
    
    [dynamicHelper_ newPostDynamicWithContent:content filesInfoArr:fileInfoArr completeHandler:^(id result, NSString *errMsg) {
        if (errMsg) {
            [weakSelf xctAssertNil:errMsg];
        }else{
            if ([result[kErrorCode]intValue] == 0) {
                NSLog(@"动态发布成功");
            }else{
                NSLog(@"动态发布失败:%@",result[kErrorMessage]);
            }
            [weakSelf xcAsyncSuccess];
        }
    } uploadProcessingHandler:^(double process) {
        NSLog(@"上传进度:%f",process);
    }];
}

/**
 *  测试上传图片，发布动态信息
 */
- (void)testPostImagesDynamicAsync{
    __weak typeof(self) weakSelf = self;
    NSString *content = @"再测发布4张图片";
    NSString *fileName1 = @"parent.png";
    NSString *imgPath1 = [[NSBundle mainBundle]pathForResource:@"parent" ofType:@"png"];
    NSString *mimeType1 = [IMB_FileHelper mimeType:imgPath1];
    NSLog(@"image1 -> mimeType:%@",mimeType1);
    NSData *imgData1 = [NSData dataWithContentsOfFile:imgPath1];
    
    NSString *fileName2 = @"ios8.png";
    NSString *imgPath2 = [[NSBundle mainBundle]pathForResource:@"ios8" ofType:@"png"];
    NSString *mimeType2 = [IMB_FileHelper mimeType:imgPath2];
    NSLog(@"image2 -> mimeType:%@",mimeType2);
    NSData *imgData2 = [NSData dataWithContentsOfFile:imgPath2];
    
    NSString *fileName3 = @"1.png";
    NSString *imgPath3 = [[NSBundle mainBundle]pathForResource:@"1" ofType:@"png"];
    NSString *mimeType3 = [IMB_FileHelper mimeType:imgPath2];
    NSLog(@"image3 -> mimeType:%@",mimeType2);
    NSData *imgData3 = [NSData dataWithContentsOfFile:imgPath3];

    NSString *fileName4 = @"jeep.jpg";
    NSString *imgPath4 = [[NSBundle mainBundle]pathForResource:@"jeep" ofType:@"jpg"];
    NSString *mimeType4 = [IMB_FileHelper mimeType:imgPath2];
    NSLog(@"image4 -> mimeType:%@",mimeType4);
    NSData *imgData4 = [NSData dataWithContentsOfFile:imgPath4];
    
    NSString *mp4FileName4 = @"parent.mp4";
    NSString *mp4FilePath4 = [[NSBundle mainBundle]pathForResource:@"parent" ofType:@"mp4"];
    NSString *mp4MimeType4 = [IMB_FileHelper mimeType:imgPath2];
    NSLog(@"mp4 -> mimeType:%@",mp4MimeType4);
    NSData *mp4FileData4 = [NSData dataWithContentsOfFile:imgPath2];
    
    
    // 封装三张图片
    NSArray *fileInfoArr = @[
                             @{kFileName:fileName1,kFileData:imgData1,kFileMimeType:FILE_MIME_TYPE_FOR_PNG},
                             @{kFileName:fileName2,kFileData:imgData2,kFileMimeType:FILE_MIME_TYPE_FOR_PNG},
                             @{kFileName:fileName3,kFileData:imgData3,kFileMimeType:FILE_MIME_TYPE_FOR_PNG},
                             @{kFileName:fileName4,kFileData:imgData4,kFileMimeType:FILE_MIME_TYPE_FOR_PNG}
                             ];
    
    
    // 封装一张图片，一个视频
    /*NSArray *fileInfoArr = @[
                             @{kFileName:fileName1,kFileData:imgData1,kFileMimeType:mimeType1},
                             @{kFileName:mp4FileName4,kFileData:mp4FileData4,kFileMimeType:mp4MimeType4}
                             ];
    */
    
    
    [dynamicHelper_ postDynamicWithSubj:content postType:ENUM_DYNAIMC_FOR_PARENT filesInfoArr:fileInfoArr completeHandler:^(id result, NSString *errMsg) {
        if (errMsg) {
            [weakSelf xctAssertNil:errMsg];
        }else{
            NSLog(@"测试发布动态内容结果：%@",result);
            [weakSelf xcAsyncSuccess];
        }
    } uploadProcessingHandler:^(double process) {
        NSLog(@"上传进度:%f",process);
    }];
}





@end
